package com.ozonetel;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @author <a href="mailto:sudhakargupta.s@gmail.com">SudhakarGupta</a>
 */
public class FLOperatorConstants {

    private Properties FLOPERATOR_CONSTANTS;
    private static volatile FLOperatorConstants INSTANCE;
    /**
     * Transient log to prevent session synchronization issues - children can
     * use instance for logging.
     */
    protected transient static final Log log = LogFactory.getLog(FLOperatorConstants.class);

    protected FLOperatorConstants() {
        FLOPERATOR_CONSTANTS = new Properties();
        try {
            FLOPERATOR_CONSTANTS.load(this.getClass().getClassLoader().getResourceAsStream("FixedLineOperators.properties"));
            log.debug("Fixed Line Operator constants are loaded successfully..");
        } catch (FileNotFoundException e) {
            log.error(e.getMessage(), e);
        } catch (IOException e) {
            log.error(e.getMessage(), e);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }

    public static FLOperatorConstants getInstance() {
        if (INSTANCE == null) {
            synchronized (FLOperatorConstants.class) {
                if (INSTANCE == null) {
                    FLOperatorConstants floperatorConstants = new FLOperatorConstants();
                    INSTANCE = floperatorConstants;
                }
            }
        }
        return INSTANCE;
    }

    public static String getConstant(String name) {
        return FLOperatorConstants.getInstance().FLOPERATOR_CONSTANTS.getProperty(name);
    }
}